<template>
  <div class="clearfix table-out">
    <div class="clearfix out-con">
      <el-button
          type="primary"
          plain
          size="small"
          class="return pointer"
          @click="returnGo"
      ><i class="iconfont icon-fanhui"></i> 返回
      </el-button>
      <top-step ref="topStepRef"></top-step>
      <div class="clear h20"></div>
      <div class="fxl left-main clearfix">
        <form-data ref="formDataRef" @getPdf="getPdf"></form-data>
      </div>
      <div class="fxr right-main clearfix">
        <div class="clearfix top_line">评委意见</div>
        <div class="pw-icon clearfix">
          <div
              class="icon fxl clearfix"
              v-for="(item, idx) in pingwlb"
              :key="idx"
          >
            <i class="iconfont icon-ps" :class="{ focus: item.yisp == 1 }"></i>
          </div>
        </div>

        <div class="pf-list clearfix" v-for="(item, idx) in pingsgz" :key="idx">
          <div class="line clearfix">
            <span class="fxl num-font"> {{ item.biaot }}</span>
            <el-input-number style="width:140px;"
                             class="fxr num-inp"
                             type="number"
                             :precision="2"
                             :min="1"
                             :max="item.zuidfz"
                             v-model="guizfs[item.id]"
                             @blur="onBlur"
                             @input="onBlur"/>
          </div>
          <div class="intro">{{ item.miaos }}</div>
        </div>
        <div class="clearfix">
          <strong>总分: </strong><span style="font-size:18px;font-weight: bold;" class="font-red">{{ zongf }}</span>
        </div>
        <div class="clarfix h20"></div>
        <p><strong>评语：</strong></p>
        <div class="clarfix h10"></div>
        <el-input
            type="textarea"
            :rows="4"
            placeholder="请输入内容"
            v-model="pingy"
        >
        </el-input>
        <div class="clear h20"></div>
        <div class="but-out clearfix">
          <el-button class="submit-big" type="primary" @click="submit"
          >专家评分
          </el-button
          >
        </div>
      </div>
      <div class="clear h20"></div>
      <form-data-pdf
          v-show="pdfStatic"
          :pdfTitle="pdfTitle"
          :pdf-title-sub="pdfTitleSub"
          :form-data="pdfData"
          ref="formDataPdfRef"
      ></form-data-pdf>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import pubJs from "./pub";

export default {
  mixins: [pubJs],
  data() {
    return {
      userInfo: JSON.parse(localStorage.getItem("userInfo")),
      id: null,
      pingwlb: [],
      pingy: "",
      zongf: 0.0,
      guizfs: {},
      pingsgz: [],
      formData2: {},
      canszpId: null,
      formData: {},
      formDefine: [],
      daqsc: null,
      saisId: null,

      topData: [],
      menuSelect: 0,
      activeName: 0,
    };
  },

  inject: ["imageUrl", "serviceUrl"],

  mounted() {

    this.saisqyId = this.$route.query.saisqyId;
    this.saisjcId = this.$route.query.saisjcId;
    this.id = this.$route.query.id;
    this.canszpId = this.$route.query.canszpId;
    this.saisId = this.$route.query.saisId;

    this.$refs["topStepRef"].getList(
        {
          saisId: this.saisId,
        },
        "pings"
    );
    this.$refs["formDataRef"].getFormDefine(
        {
          saisId: this.saisId,
          cansrsf: this.userInfo.cansrsf,
        },
        "pings"
    );
    this.$refs["formDataRef"].getFormData(
        {
          saisId: this.saisId,
          canszpId: this.canszpId,
        },
        "pings"
    );

    let that = this;

    // 评委列表
    axios
        .get(that.serviceUrl + "/saisjczd2/cbda2Saisjczd/getPingwlb", {
          headers: {
            "X-Access-Token": localStorage.getItem("token"),
          },
          params: {
            zuopId: that.canszpId,
            saisjcId: that.saisjcId,
            quyId: that.saisqyId,
            saisId: that.saisId,
            _t: new Date().getTime(),
          },
        })
        .then((resp) => {
          that.pingwlb = resp.data.result;
        })
        .catch((error) => {
          //console.log(error);
        });

    // 评审规则
    axios
        .get(that.serviceUrl + "/pingsgz/cdbaPingsgz/list", {
          headers: {
            "X-Access-Token": localStorage.getItem("token"),
          },
          params: {
            _t: new Date().getTime(),
          },
        })
        .then((resp) => {
          resp.data.result.records.forEach(item => {
            that.pingsgz.push({...item, num: 0})
          })
        })
        .catch((error) => {
          //console.log(error);
        });
    console.log(this.zongf,'this.zongf*********');
    // 历史评分
    axios
        .get(that.serviceUrl + "/pingsxq/cbda2Pingsxq/list", {
          headers: {
            "X-Access-Token": localStorage.getItem("token"),
          },
          params: {
            createBy: that.userInfo.username,
            zuopId: that.canszpId,
            _t: new Date().getTime(),
          },
        })
        .then((resp) => {
          this.zongf = 0
          let arr = []
          if (resp && resp.data.code == 200 && resp.data.result.records.length > 0) {
            resp.data.result.records.forEach(item => {
              arr.push({id: item.pingfxId, num: item.fenz})
            })
          }
          arr.forEach(item => {
            this.zongf += item.num / 1
            this.guizfs[item.id] = item.num
          })
          console.log(this.zongf,'this.zongf*********111');
        })
        .catch((error) => {
          //console.log(error);
        });

  },
  computed: {},
  methods: {
    onBlur() {
      this.zongf = 0.0;
      for (let key in this.guizfs) {
        if (this.guizfs.hasOwnProperty(key)) {
          // 确保只迭代对象自身的属性，而不是原型链上的属性
          this.zongf += parseFloat(this.guizfs[key]);
        }
      }
    },
    // handleInputChange(value, index) {
    //   this.pingsgz[index].num = value;
    //   this.zongf = 0
    //   this.pingsgz.forEach(item=>{
    //     this.zongf += item.num
    //   })
    //   console.log(this.zongf,'this.zongf');
    // },

    submit() {
      let that = this;
      const config = {
        headers: {
          "X-Access-Token": localStorage.getItem("token"),
        },
      };

      let data = {
        zuopId: this.canszpId,
        pingsxq: this.guizfs,
        pingszt: "2",
        id: this.id,
        pingf: this.zongf,
        pingy: this.pingy,
        saisId: this.saisId,
        // saisjc_id: that.saisjcId
      };

      axios
          .put(
              that.serviceUrl + "/saisjczd2/cbda2Saisjczd/editPingsjl",
              data,
              config
          )
          .then((resp) => {
            console.log(resp);
            if (resp.data.success) {
              that.$message.success("成功");
              this.$router.push("/pc/review");
            } else {
              that.$message.error(resp.data.message);
            }
          })
          .catch((error) => {
            //console.log(error);
          });
    },

    menuChange(item, index) {
      this.menuSelect = index;
      console.log(item, index);
    },

    returnGo() {
      this.$router.go(-1); // 返回上一个页面
    },
  },
};
</script>

<style scoped lang="less">
.left-main {
  width: 60%;
}

.right-main {
  width: calc(40% - 70px);
  background: #fff;
  box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
  border-radius: 10px;
  padding: 20px;
}

.pf-list {
  .line {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    margin: 0px 0px 10px 0px;
  }

  .num-font {
    width: 120px;
    font-weight: bold;
  }

  .num-inp {
    width: 100px;
  }

  .intro {
    width: 100%;
    display: block;
    opacity: 0.8;
    margin: 0px 0px 20px 0px;
  }
}

.top_line {
  font-size: 18px;
  font-weight: bold;
  border-bottom: 1px dashed #ccc;
  padding: 0px 0px 5px 0px;
  margin: 0px 0px 10px 0px;
}

.pw-icon {
  .icon {
    padding: 10px;

    i {
      font-size: 30px;

      &.focus {
        color: #3967ff;
      }
    }
  }
}
</style>
